import serial
import datetime

firstreturn  = 'FF036200FF25800000000000000000000000000000000000AA00013FCCCCCD3F8000003F9C28F600000000000000023FCCCCCD3F8000003F9C28F600000000000000053FCCCCCD3F8000003F9C28F600000000000000000000000000000000000000000000FF2F'
secondreturn = 'FF036200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000A80FF030000003191C0'
makesecond =   'FF036200FF00000000000000000000000000000000000000AA00013FCCCCCD3F8000003F9C28F600000000000000023FCCCCCD3F8000003F9C28F600000000000000053FCCCCCD3F8000003F9C28F600000000000000000000000000000000000000000000EEE6'
try:
    port = 'COM3'
    bps = 9600
    timeout = 5
    com = serial.Serial(port=port, baudrate=bps)
    com.close()
    com.open()
    print('串口打开')
    while True:
        if com.in_waiting:
            data = com.read(com.in_waiting).hex()
            print(datetime.datetime.now(), '接收', data)
            if data == 'ff0300000032d1c1':
                com.write(bytes().fromhex(firstreturn))
                print(datetime.datetime.now(),'第一帧', firstreturn)
            elif data == 'ff0300320032700e':
                com.write(bytes().fromhex(makesecond))
                print(datetime.datetime.now(), '第二帧', makesecond)
            elif data == 'ff06000200003dd4':
                print('静音')
except Exception as e:
    print("异常", e)
